/**
 * 营配一体化生产管理系统 <br>
 * Created on 2009-5-9 下午04:05:27 <br>
 */
package com.rich.component.transaction;

import org.aspectj.lang.ProceedingJoinPoint;
import org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint;
import org.springframework.core.Ordered;

/**
 * .<br>
 * 
 * @author XXX <br>
 */
public class HistoryOperateInterceptor{
//	 implements Ordered
	private int order = -1;

	public Object serviceIntercept(ProceedingJoinPoint point) throws Throwable {
		System.out.println("-----进入记录历史记录的 aop:aspect拦截器");
		Object returnValue = null;

		if (point instanceof MethodInvocationProceedingJoinPoint) {
			MethodInvocationProceedingJoinPoint mpoint = (MethodInvocationProceedingJoinPoint) point;
			//  
			returnValue = mpoint.proceed(mpoint.getArgs());
		}
		try {
			System.out.println("###########记录历史数据开始");
			// service.eventLog();
			System.out.println("###########记录历史数据结束");
//			 if (true) throw new RuntimeException("拦截器中抛出异常！");
		} catch (Exception ex) {
			System.out.println("拦截器异常:" + ex.getMessage());
			// ex.printStackTrace();
			throw new RuntimeException("ex:" + ex.getMessage());
		}
		System.out.println("-----退出记录历史记录的aop:aspect拦截器");
		return returnValue;
	}

	public Object afterIntercept(ProceedingJoinPoint point) throws Throwable {
		System.out.println("进入记录历史记录的 拦截器afterIntercept");
		Object returnValue = null;

		// if (point instanceof MethodInvocationProceedingJoinPoint) {
		// MethodInvocationProceedingJoinPoint mpoint =
		// (MethodInvocationProceedingJoinPoint) point;
		// //
		// // returnValue = mpoint.proceed(mpoint.getArgs());
		// }
		try {
			System.out.println("记录历史数据开始");
			// service.eventLog();
			System.out.println("记录历史数据结束");
			// if (true) throw new RuntimeException("拦截器中抛出异常！");
		} catch (Exception ex) {
			System.out.println("拦截器异常:" + ex.getMessage());
			// ex.printStackTrace();
			throw new RuntimeException("ex:" + ex.getMessage());
		}
		System.out.println("退出记录历史记录的拦截器 afterIntercept");
		return returnValue;
	}

	public void setOrder(int order) {
		System.out.println("set order:" + order);
		this.order = order;
	}

	public int getOrder() {
		System.out.println("get order:" + order);
		return order;
	}
}
